package com.kzj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kzj.dao.CourseRestrictedMajorsDao;
import com.kzj.domain.CourseRestrictedMajors;
import com.kzj.global.constant.GlobalConstant;
import com.kzj.service.CourseRestrictedMajorsService;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CourseRestrictedMajorsServiceImpl extends ServiceImpl<CourseRestrictedMajorsDao, CourseRestrictedMajors> implements CourseRestrictedMajorsService {
    public String getRestrictedMajorsByCourseId(String courseInformationId)
    {
        List<String> majors = this.query().eq("course_information_id", courseInformationId).list().stream().map(item->item.getMajorId()).collect(Collectors.toList());
        if(majors.isEmpty())
            return GlobalConstant.COURSE_RESTRICTED_MAJORS_GENERAL_ELECTIVE_COURSE;
        return StringUtil.join(majors,",");
    }
}
